package com.zrwl.poscloud.core.restapi.admin.baseInfo;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zrwl.poscloud.xo.service.NoticeService;
import com.zrwl.poscloud.xo.vo.NoticeVO;
/**
 * 公告发布 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-03-09
 */
@RestController
@Api(value = "公告发布相关接口", tags = {"公告发布相关接口"})
@RequestMapping("/notice")
@Slf4j
public class NoticeRestApi {
    @Autowired
    private NoticeService noticeService;
    @AuthorityVerify
    @ApiOperation(value = "获取公告发布列表", notes = "获取公告发布列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody NoticeVO noticeVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取公告发布列表: {}", noticeVO);
        return ResultUtil.successWithData(noticeService.getPageList(noticeVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取公告发布列表", notes = "获取公告发布列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody NoticeVO noticeVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取公告发布列表: {}", noticeVO);
        return ResultUtil.successWithData(noticeService.getAllList(noticeVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "新增公告发布")    @ApiOperation(value = "新增公告发布", notes = "新增公告发布", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody NoticeVO noticeVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增公告发布: {}", noticeVO);
        return noticeService.add(noticeVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "修改公告发布")    @ApiOperation(value = "修改公告发布", notes = "修改公告发布", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody NoticeVO noticeVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改公告发布: {}", noticeVO);
        return noticeService.edit(noticeVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除公告发布")    @ApiOperation(value = "删除公告发布", notes = "删除公告发布", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody NoticeVO noticeVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除公告发布: {}", noticeVO);
        return noticeService.delete(noticeVO);
    }

}
